{{define "authorizedapp"}}
{{template "top" .}}

<div class="card shadow-sm">
  <div class="card-header">
    {{if .new}}
      New Authorized Health Authority
    {{else}}
      Edit Health Authority <span class="fw-bold font-monospace">{{.app.AppPackageName}}</span>
    {{end}}
  </div>

  <div class="card-body">
    <form method="POST" action="/app" class="m-0 p-0">
      <input type="hidden" name="key" value="{{.previousKey}}" />

      <div class="row g-3">
        <div class="col-12">
          <div class="form-floating">
            <input type="text" name="app-package-name" id="app-package-name" value="{{.app.AppPackageName}}" class="form-control" placeholder="Health Authority ID">
            <label for="app-package-name" class="form-label">Health Authority ID</label>
          </div>
          <div class="form-text text-muted">
            This exact string must be passed by clients. Reverse DNS is recommended,
            but not required.
          </div>
        </div>

        <div class="col-12">
          <div class="form-floating">
            <textarea name="regions" id="regions" rows="3" class="form-control" placeholder="Regions">{{.app.RegionsOnePerLine}}</textarea>
            <label for="regions" class="form-label">Regions</label>
          </div>
          <div class="form-text text-muted">
            One per line. TEKs uploaded by this health authority will be present in
            all configurd regions (v1 API).
          </div>
        </div>

        <div class="col-12">
          <div class="form-floating">
            <select name="bypass-revision-token" id="bypass-revision-token" class="form-select">
              <option value="false" {{if not .app.BypassRevisionToken}}selected{{end}}>false</option>
              <option value="true" {{if .app.BypassRevisionToken}}selected{{end}}>true</option>
            </select>
            <label for="bypass-revision-token" class="form-label">Disable Revision Token Enforcement</label>
          </div>
          <div class="form-text text-muted">
            If true, the server will accept revised keys without a token. <strong>You
            should never disable this on a production system!</strong>
          </div>
        </div>

        <div class="col-12">
          <div class="form-floating">
            <select name="bypass-health-authority-verification" id="bypass-health-authority-verification" class="form-select">
              <option value="false" {{if not .app.BypassHealthAuthorityVerification}}selected{{end}}>false</option>
              <option value="true" {{if .app.BypassHealthAuthorityVerification}}selected{{end}}>true</option>
            </select>
            <label for="bypass-health-authority-verification" class="form-label">Disable Health Authority Verification</label>
          </div>
          <div class="form-text text-muted">
            If true, the server not verify that uploaded keys came from a health
            authority. <strong>You should never disable this on a production
            system!</strong>
          </div>
        </div>

        {{if .has}}
          <div class="col-12">
            <label>Health Authority Certificates to accept</label>
            <ul class="list-group">
              {{range .has}}
                <li class="list-group-item list-group-item-action">
                  <div class="form-check">
                    <input type="checkbox" name="health-authorities" value="{{.ID}}" id="ha{{.ID}}"
                      class="form-check-input" {{if index $.usedHealthAuthorities .ID}}checked{{end}}>
                    <label for="ha{{.ID}}" class="form-check-label d-block user-select-none">
                      {{.Name}} (<span class="font-monospace">id: {{.ID}}, iss: {{.Issuer}}, aud: {{.Audience}}</span>)
                    </label>
                  </div>
                </li>
              {{end}}
            </ul>
          </div>
        {{else}}
          <div class="alert alert-danger" role="alert">
            There are no health authorities configured.
          </div>
        {{end}}

        <div class="d-grid col-12">
          <button type="submit" class="btn btn-primary" name="action" value="save">Save changes</button>
        </div>
      </div>

      {{if not .new}}
        <div class="col-12">
          <button type="submit" name="action" value="delete" class="btn btn-link btn-sm text-danger">Delete</button>
        </div>
      {{end}}
    </form>
  </div>
</div>

{{template "bottom" .}}
{{end}}
